import 'package:get/get.dart';
import 'package:sprintf/sprintf.dart';
import 'package:yt_devops/model/device_model.dart';
import 'package:yt_devops/pages/alarm/alarm_home/alarm_list/alarm_list_model.dart';
import 'package:yt_devops/pages/devices/device_list/device_list_model.dart';
import 'package:yt_devops/pages/devices/device_tab/model/device_item_model.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/utils/enums.dart';
import 'package:yt_devops/utils/formats.dart';

class DeviceBaseInfoWidgetModel {
  DeviceModel deviceModel;

  Map<int, DeviceListModel> deviceIdMap = {}; //产品id和设备id对应关系

  DeviceBaseInfoWidgetModel(this.deviceModel, this.deviceIdMap) {
    topList = getTopList(deviceModel);
    bottomList = getBottomList(deviceModel);
    deviceInfoList = getDeviceInfoList();
  }

  List<DetailItemModel> topList = [];

  List<DetailItemModel> bottomList = [];

  List<DetailItemModel> deviceInfoList = [];

  Map<String, DetailItemModel> allItemList = {
    'ipAddress': DetailItemModel(
      field: 'adr',
      label: ResKey.ipAddress.tr,
    ),

    'margin': DetailItemModel(
      field: 'margin',
      label: 'margin',
    ),

    'ratedPower': DetailItemModel(
        field: 'ratedPower',
        label: ResKey.ratedPower.tr,
        format: Formates.powerFormat),

    'ratedOutputPower': DetailItemModel(
      field: 'ratedOutputPower',
      label: ResKey.ratedPower.tr,
    ),

    'ratedCapacity': DetailItemModel(
      field: 'ratedCapacity',
      label: ResKey.ratedCapacity.tr,
    ),

    'masterSlave': DetailItemModel(
        field: 'msid',
        label: ResKey.masterSlaveMark.tr,
        format: (value) {
          if (value.toString() == '1') {
            return ResKey.host.tr;
          } else {
            return ResKey.slave.tr;
          }
        }),

    'deviceCode': DetailItemModel(
      field: 'devid',
      label: '${ResKey.deviceDevice.tr} ID',
    ),

    'externalIpAddress': DetailItemModel(
      field: 'nadr',
      label: ResKey.externalIp.tr,
    ),

    'emsSn': DetailItemModel(
      field: 'sn',
      label: 'EMS SN',
      // 'value': '--',
      // "accessType": "deviceBaseInfo",
    ),

    'sn': DetailItemModel(
      field: 'sn',
      label: ResKey.deviceSn.tr,
      // 'value': '--',
      // "accessType": "deviceBaseInfo",
    ),

    'emsHardwareVersion': DetailItemModel(
      field: 'hv',
      label: sprintf(ResKey.deviceHardwareVersionSentence.tr, ['EMS']),
    ),

    'emsSoftwareVersion': DetailItemModel(
      field: 'softVersion',
      label: sprintf(ResKey.deviceSoftwareVersionSentence.tr, ['EMS']),
    ),

    'imeiNumber': DetailItemModel(
      field: 'imei',
      label: ResKey.imei.tr,
    ),

    'upperComputerCommunication': DetailItemModel(
        field: 'e601',
        label: sprintf(ResKey.deviceCommunicationSentence.tr,
            [ResKey.deviceUpperComputer.tr]), //上位机通信
        format: Formates.onlineStatus1),

    'cloudPlatformCommunication': DetailItemModel(
      field: 'e603',
      label: sprintf(ResKey.deviceCommunicationSentence.tr,
          [ResKey.deviceCloudPlatform.tr]), //云平台通信
      format: Formates.onlineStatus1,
      show: (value, model) => ![
        ProductIDType.newLiquidCoolingEnergyEms.value,
        ProductIDType.newAirCoolingEnergyEms.value,
        ProductIDType.FGCCEnergyEms.value,
        ProductIDType.smallEnergyEms.value,
        ProductIDType.liquidEnergy232Ems.value,
        ProductIDType.zqEms.value,
        ProductIDType.liquidEmsGrid.value,
        ProductIDType.windEmsGrid.value,
        ProductIDType.liquid215CustomEms.value,
        ProductIDType.lquid232CustomEms.value,
      ].contains(model?.productId),
    ),

    'thirdCloudPlatformCommunication': DetailItemModel(
      label: sprintf(ResKey.deviceCommunicationSentence.tr,
          [ResKey.deviceThirdCloudPlatform.tr]), //云平台通信,
      field: 'e603',
      format: Formates.onlineStatus1,
    ),

    'e709': DetailItemModel(
        field: 'e709',
        label: '',
        format: Formates.onlineStatus1,
        show: (value, model) => [
              ProductIDType.newLiquidCoolingEnergyEms.value,
              ProductIDType.newAirCoolingEnergyEms.value,
              ProductIDType.FGCCEnergyEms.value,
              ProductIDType.smallEnergyEms.value,
              ProductIDType.zqEms.value,
              ProductIDType.liquidEmsGrid.value,
              ProductIDType.windEmsGrid.value,
              ProductIDType.liquid215CustomEms.value,
              ProductIDType.lquid232CustomEms.value,
            ].contains(model?.productId)),

    'lightBoardCommunication': DetailItemModel(
        field: 'e607',
        label: sprintf(ResKey.deviceCommunicationSentence.tr,
            [ResKey.deviceLightBoard.tr]), //灯板通讯
        format: Formates.onlineStatus1),

    'emsCommunicationMethod': DetailItemModel(
        field: 'comm',
        label: sprintf(
            ResKey.deviceCommunicationMethodSentence.tr, ['EMS']), //与ems通讯方式
        format: (value) {
          if (value.toString() == '0') {
            return 'RS485';
          } else {
            return ResKey.unknown.tr;
          }
        }),

    'pcsPModelName': DetailItemModel(field: "modelName", label: ''),
    // 机型名称

    'pcsPN': DetailItemModel(field: "PN", label: ''),

    'pcsOrderID': DetailItemModel(field: "orderID", label: ''),
    //机型ID

    'pcsPvNum': DetailItemModel(field: "pvNum", label: ''),
    //组串个数

    'pcsPv1': DetailItemModel(field: "pv1", label: ''),
    // MPPT个数

    'bcmuSn': DetailItemModel(field: 'b105', label: 'BCMU SN'),

    'bcmuManufacturer': DetailItemModel(
        field: 'b106',
        label: sprintf(ResKey.deviceManufacturerSentence.tr, ['BCMU'])
        // label: 'BCMU${ResKey.manufacturer.tr}',
        ), //厂商

    'bcmuModel': DetailItemModel(
        field: 'b107', label: sprintf(ResKey.deviceModelSentence.tr, ['BCMU'])
        // label: 'BCMU${ResKey.model.tr}',
        ), //型号

    'bcmuHardwareVersion': DetailItemModel(
      field: 'hv',
      label: sprintf(ResKey.deviceHardwareVersionSentence.tr, ['BCMU']),
      show: (value, model) =>
          model?.productId != ProductIDType.smallEnergyBatteryCluster.value &&
          model?.productId != ProductIDType.pvEnergyBms.value,
    ),

    'bcmuSoftwareVersion': DetailItemModel(
      field: 'softVersion',
      label: sprintf(ResKey.deviceSoftwareVersionSentence.tr, ['BCMU']),
      show: (value, model) =>
          model?.productId != ProductIDType.smallEnergyBatteryCluster.value &&
          model?.productId != ProductIDType.pvEnergyBms.value,
    ),

    'bmuNumber': DetailItemModel(
      field: 'b121',
      label: ResKey.deviceBmuNumber.tr,
    ),

    'airHardwareVersion': DetailItemModel(
      field: 'hv',
      label: sprintf(
          ResKey.deviceHardwareVersionSentence.tr, [ResKey.deviceAir.tr]),
      show: (value, model) =>
          model?.productId != ProductIDType.smallEnergyAir.value &&
          model?.productId != ProductIDType.pvEnergyAir.value,
    ),

    'airSoftwareVersion': DetailItemModel(
      field: 'softVersion',
      label: sprintf(
          ResKey.deviceSoftwareVersionSentence.tr, [ResKey.deviceAir.tr]),
    ),

    'liquidCoolerHardwareVersion': DetailItemModel(
      field: 'hv',
      label: sprintf(ResKey.deviceHardwareVersionSentence.tr,
          [ResKey.deviceLiquidCooler.tr]),
    ),

    'liquidCoolerSoftwareVersion': DetailItemModel(
      field: 'softVersion',
      label: sprintf(ResKey.deviceSoftwareVersionSentence.tr,
          [ResKey.deviceLiquidCooler.tr]),
    ),

    'compressorSoftwareVersion': DetailItemModel(
      label: sprintf(ResKey.deviceSoftwareVersionSentence.tr,
          [ResKey.deviceCompressor.tr]),
      field: 'y2',
    ),

    'softwareCoding': DetailItemModel(
      label: ResKey.deviceSoftwareCoding.tr,
      field: 'y3',
    ),

    'fireFightingHardwareVersion': DetailItemModel(
      field: 'hv',
      label: sprintf(ResKey.deviceHardwareVersionSentence.tr,
          [ResKey.deviceFireFighting.tr]),
    ),

    'fireFightingSoftwareVersion': DetailItemModel(
      field: 'softVersion',
      label: sprintf(ResKey.deviceSoftwareVersionSentence.tr,
          [ResKey.deviceFireFighting.tr]),
    ),

    'dehumidifierHardwareVersion': DetailItemModel(
      field: 'hv',
      label: sprintf(ResKey.deviceHardwareVersionSentence.tr,
          [ResKey.deviceDehumidifier.tr]),
    ),

    'dehumidifierSoftwareVersion': DetailItemModel(
      field: 'softVersion',
      label: sprintf(ResKey.deviceSoftwareVersionSentence.tr,
          [ResKey.deviceDehumidifier.tr]),
    ),
    'factoryName': DetailItemModel(
      field: 'factoryName',
      label: ResKey.deviceManufacturer.tr,
    ),
    'model': DetailItemModel(
      field: 'model',
      label: ResKey.siteDeviceAccessProductModel.tr,
    ),
    'productTypeName': DetailItemModel(
      field: 'productTypeName',
      label: ResKey.siteDeviceAccessProductType.tr,
    ),
    'gunNumber': DetailItemModel(
      field: 'gunNumber',
      label: ResKey.chargeGunNum.tr,
    ),

    'chargeGunNumber': DetailItemModel(
      field: 'gunNumVal',
      label: ResKey.chargeGunNum.tr,
    ),

    'terminalNumber': DetailItemModel(
      field: 'tcuNumVal',
      label: ResKey.chargeTerminal.tr, //终端数量,
    ),

    'tsinglelinemaxI': DetailItemModel(
      field: 'tsinglelinemaxI',
      label: '',
    ),

    'tsn': DetailItemModel(
      field: 'tsn',
      label: '',
    ),

    'thardver': DetailItemModel(
      field: 'thardver',
      label: '',
    ),

    'softVersion': DetailItemModel(
      field: 'softVersion',
      label: '',
    ),

    'tcuct': DetailItemModel(
      field: 'tcuct',
      label: '',
    ),

    'tlocalip': DetailItemModel(
      field: 'tlocalip',
      label: '',
    ),

    'tsts': DetailItemModel(
      field: 'tsts',
      label: '',
    ),

    'msn': DetailItemModel(
      field: 'msn',
      label: '',
    ),

    'mhardver': DetailItemModel(
      field: 'mhardver',
      label: '',
    ),

    'mpcuv': DetailItemModel(
      field: 'mpcuv',
      label: '',
    ),

    'mpcuc': DetailItemModel(
      field: 'mpcuc',
      label: '',
    ),

    'tccuaconnect': DetailItemModel(
      field: 'tccuaconnect',
      label: '',
    ),

    'tccubconnect': DetailItemModel(
      field: 'tccubconnect',
      label: '',
    ),

    'tcloundconnet': DetailItemModel(
      field: 'tcloundconnet',
      label: '',
      productTypeId: ProductType.chargeMaster.value,
    ),

    'tappnet': DetailItemModel(
      field: 'tappnet',
      label: '',
    ),

    'tnets': DetailItemModel(
      field: 'tnets',
      label: '',
    ),

    'tnetprod': DetailItemModel(
      field: 'tnetprod',
      label: '',
    ),

    'timsi': DetailItemModel(
      field: 'timsi',
      label: '',
    ),

    'tstu': DetailItemModel(
      field: 'tstu',
      label: '',
    ),

    'tsigStre': DetailItemModel(
      field: 'tsigStre',
      label: '',
      productTypeId: ProductType.chargeMaster.value,
    ),

    'tnetreg': DetailItemModel(
      field: 'tnetreg',
      label: '',
      productTypeId: ProductType.chargeMaster.value,
    ),

    'mccucon': DetailItemModel(
      field: 'mccucon',
      label: '',
    ),

    'mccutype': DetailItemModel(
      field: 'mccutype',
      label: '',
    ),

    'tpcuconnect': DetailItemModel(
      field: 'tpcuconnect',
      label: '',
    ),

    'gsn': DetailItemModel(
      field: 'gsn',
      label: '',
    ),

    'ghardversion': DetailItemModel(
      field: 'ghardversion',
      label: '',
    ),

    'gccusoftVersion': DetailItemModel(
      field: 'gccusoftVersion',
      label: '',
    ),

    'gccucompt': DetailItemModel(
      field: 'gccucompt',
      label: '',
    ),

    'gtcuconnect': DetailItemModel(
      field: 'gtcuconnect',
      label: '',
    ),

    'gtcucontype': DetailItemModel(
      field: 'gtcucontype',
      label: '',
    ),

    'gpcuconnect': DetailItemModel(
      field: 'gpcuconnect',
      label: '',
    ),

    'gpcucontype': DetailItemModel(
      field: 'gpcucontype',
      label: '',
    ),

    'MCUhv': DetailItemModel(
      field: 'MCUhv',
      label: '',
    ),

    'MCUsv': DetailItemModel(
      field: 'MCUsv',
      label: '',
    ),

    'bootloaderVersion': DetailItemModel(
      field: 'bootloaderVersion',
      label: '',
    ),
    'iccid': DetailItemModel(
      label: 'ICCID',
      field: 'iccid',
    ),
    'bauSN': DetailItemModel(
      label: 'BAU SN',
      field: 'b105',
    ),
    'bauManufacturer': DetailItemModel(
      label: sprintf(ResKey.deviceManufacturerSentence.tr, ['BAU']),
      field: 'b106',
    ),
    'bauModel ': DetailItemModel(
      label: sprintf(ResKey.deviceModelSentence.tr, ['BAU']),
      field: 'b107',
    ),
    'bauHardwareVersion': DetailItemModel(
      label:
          sprintf(ResKey.deviceHardwareVersionSentence.tr, ['BAU']), // BAU硬件版本
      field: 'hv',
    ),
    'bauSoftwareVersion': DetailItemModel(
      label:
          sprintf(ResKey.deviceSoftwareVersionSentence.tr, ['BAU']), // BAU软件版本
      field: 'softVersion',
    ),
    'bsNumber': DetailItemModel(
      label: ResKey.deviceBsNumber.tr, // 电池簇个数
      field: 'batteryCount',
    ),

    'meterSerialNumber': DetailItemModel(
        label: ResKey.deviceMeterNumber.tr,
        field: 'MeterSerialNumber',
        show: (_, data) => [95, 96].contains(data?.productId),
        format: (value) => value == 1
            ? ResKey.deviceInverterMeter.tr
            : value == 2
                ? ResKey.deviceGridMeter.tr
                : ''),

    'hardwareVersion': DetailItemModel(
      label: ResKey.deviceHardwareVersion.tr,
      field: 'hv',
      show: (value, model) =>
          model?.productId != ProductIDType.smallEnergyAir.value &&
          model?.productId != ProductIDType.smallEnergyFireFight.value &&
          model?.productId != ProductIDType.pvEnergyFirFight.value,
    ),
    'softwareVersion': DetailItemModel(
      label: ResKey.deviceSoftwareVersion.tr,
      field: 'softVersion',
      show: (value, data) =>
          data?.productId != ProductIDType.smallEnergyAir.value &&
          data?.productId != ProductIDType.smallEnergyFireFight.value &&
          data?.productId != ProductIDType.pvEnergyFirFight.value,
    ),
    'inverterCommunicationMethod': DetailItemModel(
        label: sprintf(
            ResKey.deviceCommunicationSentence.tr, [ResKey.deviceInverter.tr]),
        field: 'comm',
        format: (value) {
          if (value.toString() == '0') {
            return 'RS485';
          } else {
            return ResKey.unknown.tr;
          }
        }),
    //A型光储型站控ems
    'loaclEmsSN': DetailItemModel(
      label: '',
      field: 'EMSSN',
    ),
    //A型光储型站控ems
    'loaclEmsType': DetailItemModel(
      label: '',
      field: 'EMSType',
    ),
    'mpptNum': DetailItemModel(
      label: '',
      field: 'MPPTNum',
    ),
    //固件版本
    'firmwareVersion': DetailItemModel(
      label: '',
      field: 'firmwareVersion',
    ),
  };

//下级设备
  List<String> emsKeys = [
    'ipAddress',
    'ratedOutputPower',
    'ratedCapacity',
    'masterSlave',
    'e710',
    'deviceCode',
    'externalIpAddress',
    'emsSn',
    'emsHardwareVersion',
    'emsSoftwareVersion',
    'imeiNumber',
    'iccid',
    'upperComputerCommunication',
    'cloudPlatformCommunication',
    'e709',
    'lightBoardCommunication'
  ];

  List<String> localEmsKeys = [
    'loaclEmsSN',
    'loaclEmsType',
    'emsHardwareVersion',
    'emsSoftwareVersion',
    'ipAddress',
    'externalIpAddress',
    'imeiNumber',
  ];

  List<String> fgccEmsKeys = [
    'ipAddress',
    'ratedOutputPower',
    'ratedCapacity',
    'masterSlave',
    'deviceCode',
    'externalIpAddress',
    'emsHardwareVersion',
    'emsSoftwareVersion',
    'MCUhv',
    'MCUsv',
    'bootloaderVersion',
    'imeiNumber',
    'iccid',
    'thirdCloudPlatformCommunication',
    'lightBoardCommunication',
  ];

  List<String> pcsKeys = [
    'ratedOutputPower',
    'emsCommunicationMethod',
  ];

  List<String> hwPcsKeys = [
    'ratedOutputPower',
    'emsCommunicationMethod',
    'pcsPModelName',
    'pcsPN',
    'pcsOrderID',
    'pcsPvNum',
    'pcsPv1'
  ];

  List<String> bmsKeys = [
    'bcmuSn',
    'bcmuManufacturer',
    'bcmuModel',
    'bcmuHardwareVersion',
    'bcmuSoftwareVersion',
    'emsCommunicationMethod',
    'bmuNumber',
  ];

  List<String> fgccStackKeys = [
    'bauSn',
    'bauManufacturer',
    'bauModel',
    'bauHardwareVersion',
    'bauSoftwareVersion',
    'bsNumber',
    'emsCommunicationMethod',
  ];

  List<String> airKeys = [
    'airHardwareVersion',
    'airSoftwareVersion',
    'emsCommunicationMethod'
  ];

  List<String> liquidCoolerKeys = [
    'liquidCoolerHardwareVersion',
    'liquidCoolerSoftwareVersion',
    'softwareCoding',
    'compressorSoftwareVersion',
    'emsCommunicationMethod',
  ];

  List<String> fireFightKeys = [
    'hardwareVersion',
    'softwareVersion',
    'emsCommunicationMethod',
  ];

  List<String> dehumidifierKeys = [
    'dehumidifierHardwareVersion',
    'dehumidifierSoftwareVersion',
    'emsCommunicationMethod',
  ];

  List<String> chargeGunKeys = [
    'sn',
    'factoryName',
    'model',
    'productTypeName',
    'gsn',
    'ghardversion',
    'gccusoftVersion',
    'gccucompt',
    'gtcuconnect',
    'gtcucontype',
    'gpcuconnect',
    'gpcucontype'
  ];
  List<String> chargeTerminalKeys = [
    'sn',
    'factoryName',
    'model',
    'productTypeName',
    'ratedPower',
    'chargeGunNumber',
    'tsinglelinemaxI',
    'tsn',
    'thardver',
    'softVersion',
    'tcuct',
    'tlocalip',
    'tsts',
    'tpcuconnect',
    'tccuaconnect',
    'tccubconnect',
    'tappnet',
    'tnets',
    'tnetprod',
    'timsi',
    'tstu',
    'tsigStre',
    'tnetreg',
  ];
  List<String> chargeOneMasterKeys = [
    'sn',
    'factoryName',
    'model',
    'productTypeName',
    'ratedPower',
    'chargeGunNumber',
    'tsinglelinemaxI',
    'tsn',
    'thardver',
    'softVersion',
    'tcuct',
    'tlocalip',
    'tsts',
    'msn',
    'mhardver',
    'mpcuv',
    'mpcuc',
    'tccuaconnect',
    'tccubconnect',
    'tappnet',
    'tnets',
    'tnetprod',
    'timsi',
    'tstu',
    'tsigStre',
    'tnetreg',
  ];
  List<String> chargeSplitMasterKeys = [
    'sn',
    'factoryName',
    'model',
    'productTypeName',
    'ratedPower',
    'terminalNumber',
    'chargeGunNumber',
    'msn',
    'mhardver',
    'mpcuv',
    'mpcuc',
    'mccucon',
    'mccutype',
  ];

  List<String> pvEnergyPcsKeys = [
    'ratedOutputPower',
    'meterSerialNumber',
    'hardwareVersion',
    'softwareVersion',
    'emsCommunicationMethod',
  ];

  List<String> otherKeys = ['sn', 'factoryName', 'productModel', 'productType'];

  List<String> dynamoKeys = [
    'sn',
    'factoryName',
    'productModel',
    'productType',
    'ratedOutputPower',
    'inverterCommunicationMethod'
  ];

  List<String> localEms400AKeys = [
    'loaclEmsSN',
    'loaclEmsType',
    'emsHardwareVersion',
    'emsSoftwareVersion',
    'ipAddress',
    'externalIpAddress',
    'imeiNumber'
  ];

  List<String> kTL3PVKeys = [
    'pcsPN',
    'pcsOrderID',
    'pcsPvNum',
    'mpptNum',
    'ratedOutputPower',
    'firmwareVersion',
  ];

  Map<ProductType, List<String>> get productTypeIdKeysMap => {
        ProductType.ems: emsKeys,
        ProductType.pcs: pcsKeys,
        ProductType.batteryPack: bmsKeys,
        ProductType.newBatteryPack: bmsKeys,
        ProductType.aircondition: airKeys,
        ProductType.fireFighting: fireFightKeys,
        ProductType.dehumidifier: dehumidifierKeys,
        ProductType.chargeGun: chargeGunKeys,
        ProductType.chargeTerminal: chargeTerminalKeys,
        ProductType.chargeMaster: chargeOneMasterKeys,
        ProductType.windTurbine: dynamoKeys,
        ProductType.localEms: localEmsKeys,
      };

  Map<ProductIDType, List<String>> get productIdKeysMap => {
        ProductIDType.newLiquidCoolingEnergyLiquidCooler: liquidCoolerKeys,
        ProductIDType.pvEnergyPcs: pvEnergyPcsKeys,
        ProductIDType.FGCCEnergyEms: fgccEmsKeys,
        ProductIDType.FGCCEnergyBatteryStack: fgccStackKeys,
        ProductIDType.chargeMaster: chargeSplitMasterKeys,
        ProductIDType.localEms400A: localEms400AKeys,
        ProductIDType.kTL3PV: kTL3PVKeys,
      };

  // List<Map<String, dynamic>> getTopList(DeviceModel model) {
  //   return [
  //     {
  //       "accessType": "deviceBaseInfo",
  //       'label': ResKey.communication.tr,
  //       'field': 'appConnectStatus',
  //       'format': (value) => value == 1 ? ResKey.onLine.tr : ResKey.offLine.tr,
  //     },
  //     {
  //       "accessType": "deviceBaseInfo",
  //       'label': ResKey.alarm.tr,
  //       'field': 'appWarnStatus',
  //       'format': (value) => (value as DeviceAlarmStatus).label,
  //     },
  //     {
  //       "accessType": "deviceBaseInfo",
  //       'label': ResKey.alarm.tr,
  //       'field': 'appWarnStatus',
  //       'format': (value) => (value as DeviceAlarmStatus).label,
  //     },
  //     if (model.status == 1)
  //       {
  //         "accessType": "deviceBaseInfo",
  //         'label': ResKey.recentOnlineTime.tr,
  //         'field': 'sessionStartTime',
  //         'format': (value) => value ?? '--',
  //       }
  //     else
  //       {
  //         "accessType": "deviceBaseInfo",
  //         'label': ResKey.recentOfflineTime.tr,
  //         'field': 'offlineTime',
  //         'format': (value) => model.offlineTime ?? '--',
  //       },
  //   ];
  // }
  List<DetailItemModel> getTopList(DeviceModel model) {
    return [
      DetailItemModel(
        label: ResKey.communication.tr,
        field: 'status',
        format: Formates.onlineStatus,
      ),
      DetailItemModel(
        label: ResKey.alarm.tr,
        field: 'alarmStatus',
        format: Formates.alarmFormat,
      ),
      if (model.status == 1)
        DetailItemModel(
            label: ResKey.recentOnlineTime.tr,
            field: 'sessionStartTime',
            format: (value) => value ?? '--')
      else
        DetailItemModel(
            label: ResKey.recentOfflineTime.tr,
            field: 'offlineTime',
            format: (value) => model.offlineTime ?? '--'),
      DetailItemModel(
        label: 'margin',
        field: 'margin',
      ),
    ];
  }

  List<DetailItemModel> getBottomList(DeviceModel model) {
    return [
      DetailItemModel(
        label: 'margin',
        field: 'margin',
      ),
      DetailItemModel(
        field: 'activeTime',
        label: ResKey.activationTime.tr,
        // "accessType": "deviceBaseInfo",
      ),
      DetailItemModel(
        field: 'createUserName',
        label: ResKey.enteredBy.tr,
        // "accessType": "deviceBaseInfo",
      ),
      DetailItemModel(
        field: 'createTime',
        label: ResKey.inputTime.tr,
        // "accessType": "deviceBaseInfo",
      ),
    ];
  }

  List<DetailItemModel> getDeviceInfoList() {
    List<DetailItemModel> infoList = [];
    List<String> list = otherKeys;
    if (deviceModel.productId != null &&
        deviceModel.productType != null &&
        deviceModel.productId! >=
            ProductIDType.newLiquidCoolingEnergyEms.value) {
      list = productIdKeysMap[ProductIDType.getType(deviceModel.productId!)] ??
          productTypeIdKeysMap[ProductType.getType(deviceModel.productType!)] ??
          otherKeys;
    }
    var maps = deviceIdMap.values.fold<Map<int, int>>(
        {}, (pre, item) => pre..addAll({item.productType!: item.deviceId!}));

    for (var item in list) {
      var detailItem = allItemList[item];
      if (detailItem != null) {
        if (detailItem.productTypeId != null) {
          detailItem.deviceId = maps[detailItem.productTypeId!];
        }
        infoList.add(detailItem);
      }
    }
    return infoList;
  }
}
